#ifndef _DynLib_H__
#define _DynLib_H__

#ifdef WIN32 
#    define DYNLIB_HANDLE hInstance
#    define DYNLIB_LOAD( a ) LoadLibraryEx( a, NULL, LOAD_WITH_ALTERED_SEARCH_PATH )
#    define DYNLIB_GETSYM( a, b ) GetProcAddress( a, b )
#    define DYNLIB_UNLOAD( a ) !FreeLibrary( a )
struct HINSTANCE__;
typedef struct HINSTANCE__* hInstance;
#elif
#    define DYNLIB_HANDLE void*
#    define DYNLIB_LOAD( a ) dlopen( a, RTLD_LAZY | RTLD_GLOBAL)
#    define DYNLIB_GETSYM( a, b ) dlsym( a, b )
#    define DYNLIB_UNLOAD( a ) dlclose( a )
#endif

#include <string>

class CDynLib 
{
protected:
    std::string m_Name;
    /// Gets the last loading error
    std::string DynlibError(void);
public:
    // Default constructor - used by DynLibManager.
    CDynLib( const std::string& name );

    // Default destructor.
    ~CDynLib();

    // Load the library
    bool Load();
    // Unload the library
    void Unload();
    // Get the name of the library
    const std::string & GetName(void) const { return m_Name; }

    // Returns the address of the given symbol from the loaded library
    void* GetSymbol( const std::string & strName ) const throw();

protected:

    /// Handle to the loaded library.
    DYNLIB_HANDLE m_hInst;
};

#endif
